package figure8.GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Locale;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import figure8.Controller;
import figure8.Track;
import figure8.WAVTrack;
import figure8.GUI.EffectWindow.Effect;

public class DistortionPanel extends EffectPanel {

	final JKnob distKnob;
	final JKnob gainKnob;
	final EffectPanel effPan = this;
	final EffectWindow effWindow;
	Color BG = Color.ORANGE;
	Color FG = Color.BLACK;
	
	public DistortionPanel(EffectWindow effWin){ this(effWin, Effect.DISTORTION, 0.5, 1.0 ); }

	public DistortionPanel(EffectWindow effWin, Effect effType, double distSet, double gainSet){
		super(effType, effWin);
		this.effWindow = effWin;
		
		JPanel background = new JPanel();
		background.setBackground(BG);
		background.setForeground(FG);

		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new GridBagLayout());
		titlePanel.setBackground(BG);
		titlePanel.setForeground(FG);

		//DELETE
		JLabel del = new JLabel("x");
		del.setForeground(FG);
		del.setFont(new Font(Font.DIALOG, Font.BOLD, 15));
		
		del.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {	}
			public void mouseEntered(MouseEvent arg0) {	}
			public void mouseExited(MouseEvent arg0) { }
			public void mouseReleased(MouseEvent arg0) { }
			public void mousePressed(MouseEvent arg0) {
				effWindow.effPanelDeletion(effPan);
			}
		});
		
		//TITLE
		JLabel title = 
		new JLabel("     " + "DISTORTION", JLabel.CENTER);
		title.setFont(new Font(Font.SERIF,Font.BOLD, 20));
		title.setPreferredSize(new Dimension(220, 20));
		title.setForeground(FG);
		
		GridBagConstraints a = new GridBagConstraints();
		a.fill = GridBagConstraints.BOTH;
		a.anchor = a.CENTER;
		a.gridwidth = GridBagConstraints.RELATIVE;
		titlePanel.add(title, a);
		a.anchor = a.FIRST_LINE_END;
		a.ipadx = 30;
		a.gridwidth = GridBagConstraints.REMAINDER;
		titlePanel.add(del, a);
		
		background.add(titlePanel);
		
		JPanel knobs = new JPanel();
		knobs.setLayout(new GridLayout(1,2));
		
		//DIST COL
		JPanel distPanel = new JPanel();
		distPanel.setLayout(new BoxLayout(distPanel, BoxLayout.Y_AXIS));
		JLabel dist = new JLabel("DIST");
		dist.setFont(new Font(Font.SERIF,Font.PLAIN, 10));
		distKnob = new JKnob(distSet, FG, Color.WHITE);
		distPanel.setPreferredSize(new Dimension(75, 80));
		distPanel.add(dist, BorderLayout.CENTER);
		distPanel.add(distKnob, BorderLayout.CENTER);
		distPanel.setBackground(BG);
		
		//GAIN COL
		JPanel gainPanel = new JPanel();
		gainPanel.setLayout(new BoxLayout(gainPanel, BoxLayout.Y_AXIS));
		JLabel gain = new JLabel("GAIN", JLabel.CENTER);
		gain.setFont(new Font(Font.SERIF,Font.PLAIN, 10));
		gainKnob = new JKnob(gainSet, FG, Color.WHITE);
		gainPanel.add(gain, BorderLayout.CENTER);
		gainPanel.add(gainKnob, BorderLayout.CENTER);
		gainPanel.setPreferredSize(new Dimension(75, 80));
		gainPanel.setBackground(BG);

		knobs.add(distPanel);
		knobs.add(gainPanel);
		
		background.add(titlePanel);
		
		background.add(knobs);

		this.add(background);
	}
	
	public double getDist() { return distKnob.getPercent(); }
	
	public double getGain() { return gainKnob.getPercent(); }
	
	public double[] getSettings() {
		double[] settings = {distKnob.getPercent() , gainKnob.getPercent()};
		return settings;
	}

}
